import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-07
 * Time: 8:38
 */
class Student{
    public int age;

    public Student(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age;
    }

    @Override
    public int hashCode() {
        return Objects.hash(age);
    }
}
public class Test {
    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        System.out.println(s1==s2);
        //这里比较的是自定义对象1
        Student student = new Student(12);
        Student student1 =new Student(12);
        System.out.println(student.equals(student1));
    }
    public static void main14(String[] args) {
        String s1 = "    abab  cdcd efef  ";
        String ss = s1.trim();//将字符串左右两边的空格全部去掉
        System.out.println(ss);
        System.out.println(s1);
    }
    public static void main13(String[] args) {
        String s1 = "ababcde";
        String ss = s1.substring(2);//重第二个a的位置开始截取字符串：abccde
        System.out.println(ss);
        String sss = s1.substring(2,4);//范围要给对，不能越界 [2,4)左闭右开：ab
        System.out.println(sss);
    }
    public static void main12(String[] args) {//多次拆分
        String s1 = "name=zhangsan&age=18";
        String[] ret1 = s1.split("&");
        //多次拆分
        for (String s:ret1) {
            //ret1[0] = name=zhangsan
            //ret1[1] = age=18
            //            System.out.println(s);
            String[] ret2 =s.split("=");
            for (String ss:ret2) {
                System.out.println(ss);

            }
        }
    }
    public static void main11(String[] args) {
        String s1 = "105java zhang&san";
        String[] ret = s1.split(" |&");
       // String[] ret = s1.split("[ &]");//正则表达式

        for (String s:ret
             ) {
            System.out.println(s);

        }

    }
    public static void main10(String[] args) {
       String s1 = "hello biter welcome to bit";
//        String[] ret = s1.split(" ");//根据空格来划分
//        for (String s:ret) {
//            System.out.println(s);
//        }
//        String[] ret1 = s1.split(" ",3);//limit表示分成三组
//        for (String s:ret1) {
//            System.out.println(s);
//        }
        String[] ret2 = s1.split(" ",13);//limit表示分成13组 但是最多只能分成5组
        for (String s:ret2) {
            System.out.println(s);

        }
        String s2 = "192.168.64.2";
        String[] ret3 = s2.split("\\.");
        for (String ss:ret3) {
            System.out.println(ss);

        }
        String s3 = "192\\168\\2\\2";
        String[] ret4 = s3.split("\\\\");
        for (String sss:ret4) {
            System.out.println(sss);
        }
    }
    public static void main9(String[] args) {
        String s1 = "ababcabcdabcde";
        String s2 =s1.replace('a','T');
        System.out.println(s2);
        System.out.println(s1);
        System.out.println(s1.replace("ab","qq"));
        System.out.println(s1.replaceAll("ab","qq"));
        System.out.println(s1.replaceFirst("ab","qq"));//只换第一个ab
    }
    public static void main8(String[] args) {
        String s1 = String.format("%d-%d-%d",2022,7,7);
        System.out.println(s1);
    }
    public static void main7(String[] args) {
        String s1 = "hello";
        char[] chars = s1.toCharArray();
        for (char x:chars) {
            System.out.println(x);
        }
        System.out.println(s1);
    }














    public static void main6(String[] args) {
        String s1 = "hello";
        String s2 = s1.toUpperCase();
        System.out.println(s2);
        System.out.println(s1);
        String s3 = "HAPPY";
        String s4 = s3.toLowerCase();
        System.out.println(s4);
        System.out.println(s3);
        //改变大小写不是说把当前字符串本身的值改变 而是产生了一个新的对象
    }













    public static void main5(String[] args) {
        //把其他的数据类型变成字符串
        String s1 = String.valueOf(123);
        String s2 = String.valueOf(12.5);
        System.out.println(s1);
        System.out.println(s2);
        String s3 = String.valueOf(new Student(18));
        System.out.println(s3);
        //字符串转数字
        int a = Integer.valueOf("123");
        System.out.println(a);
        int b = Integer.valueOf("42",6);//4*6+2*1=24+2=26
        System.out.println(b);
        int c = Integer.parseInt("456");
        System.out.println(c);
        int d = Integer.parseUnsignedInt("64",8);//6*8+4=48+4=52
        System.out.println(d);
        double e = Double.parseDouble("12.2");
        System.out.println(e);
    }
    public static void main4(String[] args) {
        String s1 = "ababcab";
        int index = s1.lastIndexOf('a');//从后往前找ch第一次出现的位置
        System.out.println(index);
        index = s1.lastIndexOf('a',4);//从fromindex往前找
        System.out.println(index);//2
        index = s1.lastIndexOf("ab");
        System.out.println(index);
        index = s1.lastIndexOf("ab",3);
        System.out.println(index);
    }
    public static void main3(String[] args) {
        String s1 = "hello";
        int  index=s1.indexOf('l');//用来查找第一次出现的字符，默认是从头开始找的,返回下标
        System.out.println(index);
        index = s1.indexOf('r',4);//从formindex后面开始找目标字符
        index = s1.indexOf('l',2);//从formindex后面开始找目标字符
        System.out.println(index);
        index = s1.indexOf('l',3);//从formindex后面开始找目标字符
        System.out.println(index);
        String s2 = "ababcabcde";
        index = s2.indexOf("abcd");//查找字符串abcd第一次出现的位置 KMP算法
        System.out.println(index);
        index = s2.indexOf("ab",2);//从fromindex往后开始查找"ab"
        System.out.println(index);
    }
    public static void main2(String[] args) {
        String s1 = "hello";
        for (int i = 0; i < s1.length(); i++) {
            System.out.println(s1.charAt(i));
        }
        char ch = s1.charAt(1);//用来获取index处的字符
        System.out.println(ch);
    }
    public static void main1(String[] args) {
        String str1 = "hello";
        String str4 = "HELLO";
        String str2 = new String("nihao");
        char[] str3 = {'a','b','c'};
        System.out.println(str1.equals(str2));
        System.out.println(str1.compareTo(str2));
        System.out.println(str1.equalsIgnoreCase(str4));
        System.out.println(str1.compareToIgnoreCase(str4));

    }
}
